﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using System.Drawing;
using System.ComponentModel;

namespace Tsanie.ShellExtension.PropertySheet.UI {
    public class TextBoxEx : TextBox {
        private Label _lblText;
        [DefaultValue("(为空或者有多个值)")]
        public string EmptyText {
            get { return _lblText.Text; }
            set { _lblText.Text = value; }
        }
        public new bool Enabled {
            get { return base.Enabled; }
            set {
                base.Enabled = value;
                _lblText.BackColor = value ?
                    base.BackColor :
                    Color.FromKnownColor(KnownColor.Control);
            }
        }

        public TextBoxEx()
            : base() {
            SetStyle(ControlStyles.AllPaintingInWmPaint
                   | ControlStyles.OptimizedDoubleBuffer
                   , true);
            _lblText = new Label() {
                Location = new Point(2, 2),
                Text = "(为空或者有多个值)",
                Font = new Font(base.Font, FontStyle.Italic),
                ForeColor = Color.LightGray,
                AutoSize = true
            };
            _lblText.MouseDown += (sender, e) => { this.Focus(); };
            this.Controls.Add(_lblText);
        }

        protected override void OnTextChanged(EventArgs e) {
            base.OnTextChanged(e);
            _lblText.Visible = string.IsNullOrEmpty(base.Text);
        }
    }
}
